<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>注册</title>
  <link rel="stylesheet" href="../css/bootstrap.min.css">
  <script src="../myjs/ajax.js"></script>
  <script src="../js/jauery-1.6.1.js"></script>
  <style>
    #register {
      width: 400px;
      margin: 150px auto;
    }

    #alert_info {
      margin: 2px;
      padding: 2px;
      text-align: center;
      margin-bottom: 10px;
      display: none;
    }
  </style>
  <script>
    window.onload = function () {
      var oBtn = document.getElementById("btn1");
      var aInput = document.getElementsByTagName("input");
      var oAlert = document.getElementById("alert_info");
      // var a = document.getElementsByName("sex");
      // var val;
      // for (var i = 0; i < a.length; i++) {
      //   if (a[i].checked) { 
      //     val = a[i].value; 
      //   }
      // }
        oBtn.onclick = function () {
          $ajax({
            method: "post",
            url: "register.php",
            data: {
              username: aInput[0].value,
              sex: aInput[1].value,
              number: aInput[3].value,
              worksp:aInput[4].value,
              password: aInput[5].value,
              addTime: new Date().getTime()
            },
            success: function (result) {
              var obj = JSON.parse(result);
              if (obj.code) {
                oAlert.className = "alert alert-danger";
              } else {
                oAlert.className = 'alert alert-success';
                setTimeout(function () {
                  location.href = "login.html";
                }, 2000);
              }
              oAlert.style.display = "block";
              oAlert.innerHTML = obj.message;
            },
            error: function (msg) {
              alert(msg);
            }
          })
        }
      }
  </script>
</head>

<body
  style="background-image:url(../imgs/1.jpg);background-repeat:no-repeat;background-attachment:fixed;background-size:cover">
  <div class="container">
    <div class="panel panel-primary" id="register">
      <div class="panel-heading">
        注册
      </div>
      <div class="panel-body">
        <div class="form-group">
          <label for="username">用户名</label>
          <input type="text" name="username" class="form-control" id="">
        </div>
        <div class="form-group">
          <label for="sex">性别</label>
          <input type="radio" name="sex" id="" value="男" checked>男
          <input type="radio" name="sex" id="" value="女">女
        </div>
        <div class="form-group">
          <label for="number">身份证号</label>
          <input type="text" name="number" class="form-control" id="">
        </div>
        <div class="form-group">
          <label for="worksp">工作单位</label>
          <input type="text" name="worksp" class="form-control" id="">
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input type="text" name="password" class="form-control" id="">
        </div>
        <div class="alert alert-danger" role="alert" id="alert_info">xxx</div>
        <a href="login.html">马上登陆</a>
        <button class="btn btn-primary pull-right" id="btn1">注册</button>
      </div>
    </div>
  </div>
</body>

</html>